<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="APPLICATION_RESOURCES_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="APPLICATION_RESOURCES_GRID" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="FOLDERS_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="CURRENT_PATH_KEY" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />

<atleap:isUserInRole roles="core-applicationResource-update" var="canUpdate" />

<c:set value="${requestScope[pageScope.CURRENT_PATH_KEY]}" var="currentPath" />
<c:set var="path" value="" />
<c:if test="${currentPath.numberOfFolders> 1}">
	<atleap:iterator items="${currentPath.folders}" var="folder" end="${currentPath.numberOfFolders - 2}">
		<atleap:rewriteUrl action="/core/applicationResource/list"  var="folderLink">
			<atleap:param name="currentFolder" value="${folder.fullPath}" />
		</atleap:rewriteUrl>
		<c:set var="folderLink" value="<a href=\"${folderLink}\">${folder.name}</a>" />
	    <c:set var="path" value="${path}${folderLink}." />
    </atleap:iterator>
</c:if>
<c:if test="${currentPath.numberOfFolders> 0}">
	<c:set var="path" value="${path}${currentPath.lastFolder.name}." />
</c:if>

<c:set var="infoCells" value="2" />
<c:set var="constantButtonCells" value="0" />
<c:set var="additionalCells" value="0" />
<c:if test="${canUpdate}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>

<atleap:content identifier="information" ignore="true" />
<atleap:messages property="applicationResourceNotFound" />
<atleap:grid name="${pageScope.APPLICATION_RESOURCES_GRID}" pageSize="${pageSize}">
    <table border="0" cellpadding="0" cellspacing="0" class="grid">
        <thead>
            <tr>
                <th nowrap="nowrap" colspan="${infoCells + constantButtonCells + additionalCells}">
                    <atleap:message key="core.commons.currentPath" arg0="${path}" />
                </th>
            </tr>
            <tr>
                <th nowrap="nowrap">
                    <atleap:column fieldName="r.id.key" fieldKey="core.applicationResource.form.id.key">
                        <atleap:sort rowIterators="keyIterator">
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
						</atleap:sort>
					</atleap:column>
                </th>
                <th nowrap="nowrap">
					<atleap:message key="core.applicationResource.form.value" />
                </th>
                <c:if test="${constantButtonCells + additionalCells > 0}">
                    <th colspan="${constantButtonCells + additionalCells}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                </c:if>
            </tr>
        </thead>
        <tbody>
            <atleap:contextMenu var="folderMenuId">
                <atleap:rowsIterator tagId="folderIterator" var="folder" collection="${requestScope[pageScope.FOLDERS_COLLECTION_KEY]}" oddClass="oddRow" evenClass="evenRow">
                    <atleap:itemSet>
                        <atleap:rewriteUrl action="core/applicationResource/list" var="defaultUrl">
                            <atleap:param name="currentFolder" value="${folder.fullPath}" />
                        </atleap:rewriteUrl>
                        <tr class="${rowClass}" oncontextmenu="return showContextMenu(${folderMenuId}, event, ${indexId});" onclick="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);">
                            <td colspan="${infoCells + constantButtonCells + additionalCells}">
                                <atleap:link action="core/applicationResource/list">
                                    <atleap:param name="currentFolder" value="${folder.fullPath}" />
                                    <c:out value="${folder.name}" escapeXml="true" />
                                </atleap:link>
                            </td>
                            <atleap:item includeInPage="false">
                                <atleap:itemEnabled>
                                    <atleap:message key="core.commons.folders.openFolder" var="openFolderMsg" />
                                    <atleap:itemLink action="core/applicationResource/list" title="${openFolderMsg}">
                                        <atleap:param name="currentFolder" value="${folder.fullPath}" />
                                        <atleap:itemLabel>
                                            ${openFolderMsg}
                                        </atleap:itemLabel>
                                    </atleap:itemLink>
                                </atleap:itemEnabled>
                            </atleap:item>
                        </tr>
                    </atleap:itemSet>
                </atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:contextMenu var="menuId">
                <atleap:rowsIterator tagId="keyIterator" var="key" collection="${requestScope[pageScope.APPLICATION_RESOURCES_COLLECTION_KEY]}" oddClass="oddRow" evenClass="evenRow">
                    <atleap:itemSet>
                        <atleap:rewriteUrl action="core/applicationResource/callUpdate" var="defaultUrl">
                            <atleap:param name="key" value="${key}" />
                        </atleap:rewriteUrl>
                        <c:set var="onTrClickCode" value="" />
                        <c:set var="tdClass" value="defaultCursorCell" />
                        <c:if test="${canUpdate}">
                            <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                            <c:set var="tdClass" value="pointerCursorCell" />
                        </c:if>
                        <tr class="${rowClass}" oncontextmenu="return showContextMenu(${menuId}, event, ${indexId});" onclick="${onTrClickCode}">
                            <td class="${tdClass}">
                                <c:out value="${key}" escapeXml="true" />
                            </td>
                            <td class="${tdClass}">
                                <atleap:message key="${key}" var="keyValue" />
                                <c:out value="${keyValue}" escapeXml="true" />
                            </td>
                            <atleap:item includeInContextMenu="${canUpdate}" includeInPage="${canUpdate}">
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
                                    <atleap:itemEnabled>
                                        <atleap:itemLink action="core/applicationResource/callUpdate" title="${callUpdateMsg}">
                                            <atleap:param name="key" value="${key}" />
                                            
                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" title="${callUpdateMsg}" alt="${callUpdateMsg}" align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${callUpdateMsg}
                                                    </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                        </tr>
                    </atleap:itemSet>
                </atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
            </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                       <atleap:message key="core.grid.pager.title" />&nbsp;
                       <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                       <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                       <atleap:pagesIterator>
                           <atleap:page>${pageNumber}&nbsp;</atleap:page>
                           <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                       </atleap:pagesIterator>
                       <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                       <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
</atleap:grid>


